<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>网页开关灯</title>
	</head>
	<body>
		<input type="button" id="but" value="开关" />
	</body>
	<script>
		var but = document.getElementById('but');
		var flag = 0;
		but.onclick = function(){
			if(flag == 0){
				flag = 1;
				document.body.style.backgroundColor =  'black';
			}else{
				flag = 0;
				document.body.style.backgroundColor =  'white';
			}
		}
	</script>
</html>
